<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>用户列表 - userList</title>
		<link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css" />
	</head>
	<body>
		<div class="container-fluid">
			<div class="row">
				<div th:replace="/common/carousel::carousel"></div>
				<div th:replace="/common/nav::nav"></div>
				<div class="col-md-6 col-md-offset-3" style="min-height: 300px">
					<h1 class="text-center">用户列表</h1>
					<table class="table table-bordered">
						<thead>
							<tr>
								<th>用户ID</th>
								<th>用户姓名</th>
								<th>用户性别</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<tr th:each="user:${userList}">
								<td th:text="${user.id}"></td>
								<td th:text="${user.username}"></td>
								<td th:text="${user.usersex}"></td>
								<td>
									<a th:href="@{/user/edit?id=${user.id}}" class="btn btn-primary btn-xs">增加</a>
									<a class="btn btn-xs btn-warning" th:href="@{/editUser/{id}(id=${user.id})}">修改</a>
									<a class="btn btn-xs btn-danger" th:onclick="delUser([[${user.id}]])">删除</a>
								</td>
								<!-- @{/users/delete/{id}(id=${user.id}) -->
							</tr>
						</tbody>
					</table>
					<div class="text-center">
						<ul class="pagination pagination-md">
						    <li th:if="${nowPage}==1" class="disabled"><a href="#">上页</a></li>
							<li th:if="${nowPage}!=1"><a th:href="'/userList?page='+(${nowPage}-1)">上页</a></li>
						    <li th:each="index:${#numbers.sequence(1,totalPage)}" th:id="'page_'+${index}">
								<a th:href="'/userList?page='+${index}" th:text="${index}"></a>
							</li>
						    <li th:if="${nowPage} == ${totalPage}" class="disabled"><a href="#">下页</a></li>
							<li th:if="${nowPage} != ${totalPage}"><a th:href="'/userList?page='+(${nowPage}+1)">下页</a></li>
						</ul>
					</div>
				</div>
			</div>
		</div>
		<div th:replace="/common/footer::footer"></div>
		<script src="/js/jquery-3.6.0.min.js"></script>
		<script src="/js/bootstrap.min.js"></script>
		<script>
			function delUser(id){
				if(!confirm('是否删除？')){
					return false;
				}
				window.location.href = '/users/delete/'+id;
			}
			$('#page_[[${nowPage}]]').addClass('active');
		</script>
	</body>
</html>
